package com.musicsonar.android.bean;

import java.io.Serializable;
import java.net.URL;
import java.util.Map;

import android.text.TextUtils;

public class Song implements Serializable {

	private static final long serialVersionUID = 1L;

	private Long index;

	private String songPath;

	private Long segundos;

	private String songImage;

	private String songYT;

	private String songTitle;

	private String songDuration;

	public Song() {
		super();
	}

	public Song(Map<String, Object> data) {
		super();
		setIndex(Long.valueOf((String)data.get("index")));
		setSegundos(Long.valueOf((String)data.get("segundos")));
		setSongPath((String)data.get("songPath"));
		setSongImage((String)data.get("songImage"));
		setSongYT((String)data.get("songYT"));
		setSongTitle((String)data.get("songTitle"));
		setSongDuration((String)data.get("songDuration"));
	}

	public Long getIndex() {
		return index;
	}

	public void setIndex(Long index) {
		this.index = index;
	}

	public String getSongPath() {
		return songPath;
	}

	public void setSongPath(String songPath) {
		this.songPath = songPath;
	}

	public Long getSegundos() {
		return segundos;
	}

	public void setSegundos(Long segundos) {
		this.segundos = segundos;
	}

	public String getSongImage() {
		return songImage;
	}

	public void setSongImage(String songImage) {
		this.songImage = songImage;
	}

	public String getSongYT() {
		return songYT;
	}

	public void setSongYT(String songYT) {
		this.songYT = songYT;
	}

	public String getSongTitle() {
		return songTitle;
	}

	public void setSongTitle(String songTitle) {
		this.songTitle = songTitle;
	}

	public String getSongDuration() {
		return songDuration;
	}

	public void setSongDuration(String songDuration) {
		this.songDuration = songDuration;
	}

	public String getSongID() {
		try{
			URL url = new URL(getSongYT());
			TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter('&');
			splitter.setString(url.getQuery());
			for(String s : splitter){
				if (s.startsWith("v")) {
					String[] part = s.split("=");
					return part[1];
				}
			}
		}catch(Exception e){
			
		}
		return null;
	}
}